package com.nsl.my_youlai.fast2json_demo;


import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import enums.learn.ColorEnum;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

public class ColorEnumWriter implements ObjectWriter {


    @Override
    public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type type, long features) {
        if (object == null) {
            jsonWriter.writeNull();
            return;
        }

        ColorEnum colorEnum = (ColorEnum) object;
        Map<String,Object> map=new HashMap<>();
        map.put("value",colorEnum.getValue());
        map.put("label",colorEnum.getLabel());
        jsonWriter.write(map);
    }
}
